# -*- coding: utf-8 -*-
import os

"""
    连接数据库的配置 
"""

basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


class BaseConfig(object):
    """
    sqlite 连接方式
    """
    # # SQLite URI compatible
    # WIN = sys.platform.startswith('win')
    # if WIN:
    #     prefix = 'sqlite:///'
    # else:
    #     prefix = 'sqlite:////'
    # tzq.config['SQLALCHEMY_DATABASE_URI'] = prefix + os.path.join(os.path.dirname(tzq.root_path)
    # , os.getenv('DATABASE_FILE', 'data.db'))

    """
    postgresql 连接方式
    """
    # username = "log"
    # password = "1"
    # dbname = "log_db"
    # app.config["SQLALCHEMY_DATABASE_URI"] = f'postgresql://{username}:{password}@localhost:5432/{dbname}'
    # app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # db = SQLAlchemy(app)
    # db.init_app(app)
    # engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    # metadata = MetaData(bind=engine)

    # PostgreSQL连接配置
    username = "log"
    password = "1"
    # dbname = "log_db"
    dbname = "log_dev_db"
    SQLALCHEMY_DATABASE_URI = f'postgresql://{username}:{password}@localhost:5432/{dbname}'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    SQLALCHEMY_ENGINE_OPTIONS = {
        'pool_size': 5,
        'max_overflow': 10,
        'pool_recycle': 3600
    }

    # 邮件服务器配置
    MAIL_SERVER = 'smtp.qq.com'  # 邮件服务器（Gmail、QQ 邮箱）
    MAIL_PORT = 587  # 端口号
    MAIL_USE_TLS = True
    MAIL_USERNAME = '949819874@qq.com'  # 你的邮箱
    MAIL_PASSWORD = 'ieqakeyxxnhtbeec'  # 邮箱密码或授权码

    # MAIL_SERVER = os.getenv('MAIL_SERVER')
    # MAIL_PORT = 465
    # MAIL_USE_SSL = True
    # MAIL_USERNAME = os.getenv('MAIL_USERNAME')
    # MAIL_PASSWORD = os.getenv('MAIL_PASSWORD')
    # MAIL_DEFAULT_SENDER = ('TZQ Admin', MAIL_USERNAME)


class DevelopmentConfig(BaseConfig):
    DEBUG = True
    TEMPLATES_AUTO_RELOAD = True
    SQLALCHEMY_ECHO = True  # 开发环境显示SQL日志


class ProductionConfig(BaseConfig):
    DEBUG = False


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig
}
